//
//  HJJPlayerImageView.m
//  Pianke
//
//  Created by 黄俊杰 on 15/12/28.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "HJJPlayerImageView.h"

@implementation HJJPlayerImageView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

-(void)createView{
        
    self.PicImage = [[UIImageView alloc] init];
    [self addSubview:self.PicImage];
    [self.PicImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(20 * EACH_WIDTH);
        make.top.mas_equalTo(70 * EACH_HEIGHT);
        make.bottom.mas_equalTo(self.PicImage.mas_top).offset(335 * EACH_HEIGHT);
        make.right.mas_equalTo(-20 * EACH_WIDTH);
    }];
    //裁掉边框
    self.PicImage.layer.masksToBounds = YES;
    //设置半径
    self.PicImage.layer.cornerRadius = 167.5 * EACH_HEIGHT;
    //设置边框
    self.PicImage.layer.borderWidth = 10 * EACH_HEIGHT;
    self.PicImage.layer.borderColor = BLUECOLOR.CGColor;
    
    //延迟动画执行0.1秒,因为layer层加载需要时间.否则转盘不转
//    [self performSelector:@selector(startAnimation) withObject:self afterDelay:0.2];
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.font = MIDDLEFONT;
    self.nameLabel.textColor = GRAYCOLOR;
    self.nameLabel.textAlignment = 1;
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(3 * EACH_HEIGHT);
        make.left.mas_equalTo(self.mas_centerX).offset(-80 * EACH_WIDTH);
        make.right.mas_equalTo(self.mas_centerX).offset(80 * EACH_WIDTH);
        make.bottom.mas_equalTo(self.nameLabel.mas_top).offset(20 * EACH_HEIGHT);
    }];
}

-(void)startAnimation{

    //改变view z轴值
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //旋转的起始值,从0开始旋转
    animation.fromValue = [NSNumber numberWithInt:0];
    //最终旋转的角度是360度
    animation.toValue = [NSNumber numberWithInt:M_PI * 2];
    //旋转的时间
    animation.duration = 30;
    //重复次数,0为无限旋转
    animation.repeatCount = 100;
    //旋转结束后是否要逆向返回原位置
    animation.autoreverses = NO;
    //是否按照结束位置继续旋转
    animation.cumulative = YES;
    //给view的layer层添加动画,key是标记随便起的名
    [self.PicImage.layer addAnimation:animation forKey:@"basicAnimation"];
}

-(void)StartAnimation{

    //延迟动画执行0.1秒,因为layer层加载需要时间.否则转盘不转
    [self performSelector:@selector(startAnimation) withObject:self afterDelay:0.01];
}


@end
